package com.travelingsalesmen.post.gui;

import java.awt.event.ActionListener;
import javax.swing.JPanel;

public class PaymentPanel extends JPanel {

    private GUIPost guiPost;
    private ActionListener payListener;

    /**
     * Creates new form PaymentPanel
     */
    public PaymentPanel() {
        initComponents();
        cmbPaymentType.addItem("CASH");
        cmbPaymentType.addItem("CREDIT");
        cmbPaymentType.addItem("CHECK");
    }

    public void reset() {
        txtInput.setText("");
        cmbPaymentType.setSelectedIndex(0);
    }

    public void setPayActionListener(ActionListener payListener) {
        this.payListener = payListener;
    }

    public String getPaymentType() {
        return cmbPaymentType.getSelectedItem().toString();
    }

    public String getPaymentExtraInfo() {
        return txtInput.getText();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pnlPaymentPanel = new javax.swing.JPanel();
        lblPaymentType = new javax.swing.JLabel();
        lblTenderAmount = new javax.swing.JLabel();
        cmbPaymentType = new javax.swing.JComboBox();
        txtInput = new javax.swing.JTextField();
        btnPay = new javax.swing.JButton();

        pnlPaymentPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Payment", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 12))); // NOI18N

        lblPaymentType.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        lblPaymentType.setText("Payment Type");

        lblTenderAmount.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        lblTenderAmount.setText("Tender Amount");

        cmbPaymentType.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                itemChanged(evt);
            }
        });

        txtInput.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        txtInput.setName(""); // NOI18N

        btnPay.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        btnPay.setText("Pay ");
        btnPay.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                pay(evt);
            }
        });

        javax.swing.GroupLayout pnlPaymentPanelLayout = new javax.swing.GroupLayout(pnlPaymentPanel);
        pnlPaymentPanel.setLayout(pnlPaymentPanelLayout);
        pnlPaymentPanelLayout.setHorizontalGroup(
            pnlPaymentPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlPaymentPanelLayout.createSequentialGroup()
                .addGap(33, 33, 33)
                .addGroup(pnlPaymentPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(btnPay, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(pnlPaymentPanelLayout.createSequentialGroup()
                        .addComponent(lblPaymentType)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(cmbPaymentType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(66, 66, 66)
                        .addComponent(lblTenderAmount)
                        .addGap(27, 27, 27)
                        .addComponent(txtInput, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        pnlPaymentPanelLayout.setVerticalGroup(
            pnlPaymentPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlPaymentPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlPaymentPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblPaymentType)
                    .addComponent(lblTenderAmount)
                    .addComponent(txtInput, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cmbPaymentType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 12, Short.MAX_VALUE)
                .addComponent(btnPay, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(pnlPaymentPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(pnlPaymentPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
    }// </editor-fold>//GEN-END:initComponents

    private void pay(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_pay
        payListener.actionPerformed(null);
    }//GEN-LAST:event_pay
    private void itemChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_itemChanged
        if (cmbPaymentType.getSelectedItem().toString().equals("CASH")) {
            lblTenderAmount.setText("Amount");
        } else if (cmbPaymentType.getSelectedItem().toString().equals("CREDIT")) {
            lblTenderAmount.setText("Card Number");
        } else {
            lblTenderAmount.setText("Account number");
        }
    }//GEN-LAST:event_itemChanged
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnPay;
    private javax.swing.JComboBox cmbPaymentType;
    private javax.swing.JLabel lblPaymentType;
    private javax.swing.JLabel lblTenderAmount;
    private javax.swing.JPanel pnlPaymentPanel;
    private javax.swing.JTextField txtInput;
    // End of variables declaration//GEN-END:variables
}
